#ifndef NSSHARE_UTILS_EVENT_ADAPTER_H_
#define NSSHARE_UTILS_EVENT_ADAPTER_H_

#include <assert.h>
#include "event_handler.h"

namespace nsshare
{
namespace utils
{

template<typename T, typename A>
class EventAdapter : public EventHandler<A>
{
public:
    typedef void (T::*F)(base::BaseObject * sender, A arg);
public:
    EventAdapter()
        : obj_(0), func_(0)
    {
    }

    void Register(T * obj, F func)
    {
        obj_ = obj;
        func_ = func;
    }

    void OnEvent(base::BaseObject * sender, A arg)
    {
        assert(obj_);
        assert(func_);

        if(obj_ && func_)
            (obj_->*func_)(sender, arg);
    }

private:
    T * obj_;
    F func_;
};

}
}

#endif